package com.ruoyi.orderReturn.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.orderReturn.domain.VO.OrderUserReason;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.orderReturn.domain.OrderReturn;
import com.ruoyi.orderReturn.service.IOrderReturnService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 商品退货Controller
 *
 * @author ruoyi
 * @date 2024-12-17
 */
@RestController
@RequestMapping("/orderReturn")
public class OrderReturnController extends BaseController
{
    @Autowired
    private IOrderReturnService orderReturnService;

    /**
     * 查询商品退货列表
     */
    @RequiresPermissions("orderReturn:orderReturn:list")
    @GetMapping("/list")
    public TableDataInfo list(OrderUserReason orderReturn)
    {
        startPage();
        List<OrderReturn> list = orderReturnService.selectOrderReturnList(orderReturn);
        return getDataTable(list);
    }

    /**
     * 导出商品退货列表
     */
    @RequiresPermissions("orderReturn:orderReturn:export")
    @Log(title = "商品退货", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderUserReason orderReturn)
    {
        List<OrderReturn> list = orderReturnService.selectOrderReturnList(orderReturn);
        ExcelUtil<OrderReturn> util = new ExcelUtil<OrderReturn>(OrderReturn.class);
        util.exportExcel(response, list, "商品退货数据");
    }

    /**
     * 获取商品退货详细信息
     */
    @RequiresPermissions("orderReturn:orderReturn:query")
    @GetMapping(value = "/{returnId}")
    public AjaxResult getInfo(@PathVariable("returnId") Long returnId)
    {
        return success(orderReturnService.selectOrderReturnByReturnId(returnId));
    }

    /**
     * 新增商品退货
     */
    @RequiresPermissions("orderReturn:orderReturn:add")
    @Log(title = "商品退货", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderReturn orderReturn)
    {
        return toAjax(orderReturnService.insertOrderReturn(orderReturn));
    }

    /**
     * 修改商品退货
     */
    @RequiresPermissions("orderReturn:orderReturn:edit")
    @Log(title = "商品退货", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderReturn orderReturn)
    {
        return toAjax(orderReturnService.updateOrderReturn(orderReturn));
    }

    /**
     * 删除商品退货
     */
    @RequiresPermissions("orderReturn:orderReturn:remove")
    @Log(title = "商品退货", businessType = BusinessType.DELETE)
	@DeleteMapping("/{returnIds}")
    public AjaxResult remove(@PathVariable Long[] returnIds)
    {
        return toAjax(orderReturnService.deleteOrderReturnByReturnIds(returnIds));
    }
}
